<?php

/**
 * This is the model class for table "ganti_kartu".
 *
 * The followings are the available columns in table 'ganti_kartu':
 * @property integer $id
 * @property string $nota_no
 * @property string $endorsement_no
 * @property double $nominal
 * @property double $admin_broker
 * @property double $stamp_duty
 * @property double $stampduty_asuransi
 * @property double $discount
 * @property double $diskon_asuransi
 * @property string $due_date
 * @property double $nett_to_insurance
 * @property integer $posting
 * @property integer $type_reg_policy
 * @property integer $reg_policy_id
 * @property string $note
 * @property integer $createdby
 * @property string $createdtime
 * @property integer $updatedby
 * @property string $updatedtime
 * @property double $biaya_kartu
 * @property integer $value_brokerage
 */
class GantiKartu extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'ganti_kartu';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('nota_no', 'required'),
			array('posting, type_reg_policy, reg_policy_id, createdby, updatedby, value_brokerage', 'numerical', 'integerOnly'=>true),
			array('nominal, admin_broker, stamp_duty, stampduty_asuransi, discount, diskon_asuransi, nett_to_insurance, biaya_kartu', 'numerical'),
			array('nota_no, endorsement_no', 'length', 'max'=>50),
			array('note', 'length', 'max'=>100),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, nota_no, endorsement_no, nominal, admin_broker, stamp_duty, stampduty_asuransi, discount, diskon_asuransi, due_date, nett_to_insurance, posting, type_reg_policy, reg_policy_id, note, createdby, createdtime, updatedby, updatedtime, biaya_kartu, value_brokerage', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'nota_no' => 'Nota No',
			'endorsement_no' => 'Endorsement No',
			'nominal' => 'Nominal',
			'admin_broker' => 'Biaya Admin',
			'stamp_duty' => 'Stamp Duty',
			'stampduty_asuransi' => 'Stampduty Asuransi',
			'discount' => 'Discount',
			'diskon_asuransi' => 'Diskon Asuransi',
			'due_date' => 'Due Date',
			'nett_to_insurance' => 'Nett To Insurance',
			'posting' => 'Posting',
			'type_reg_policy' => 'Type Reg Policy',
			'reg_policy_id' => 'Reg Policy',
			'note' => 'Note',
			'createdby' => 'Createdby',
			'createdtime' => 'Createdtime',
			'updatedby' => 'Updatedby',
			'updatedtime' => 'Updatedtime',
			'biaya_kartu' => 'Biaya Kartu',
			'value_brokerage' => 'Value Brokerage',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('nota_no',$this->nota_no,true);
		$criteria->compare('endorsement_no',$this->endorsement_no,true);
		$criteria->compare('nominal',$this->nominal);
		$criteria->compare('admin_broker',$this->admin_broker);
		$criteria->compare('stamp_duty',$this->stamp_duty);
		$criteria->compare('stampduty_asuransi',$this->stampduty_asuransi);
		$criteria->compare('discount',$this->discount);
		$criteria->compare('diskon_asuransi',$this->diskon_asuransi);
		$criteria->compare('due_date',$this->due_date,true);
		$criteria->compare('nett_to_insurance',$this->nett_to_insurance);
		$criteria->compare('posting',$this->posting);
		$criteria->compare('type_reg_policy',$this->type_reg_policy);
		$criteria->compare('reg_policy_id',$this->reg_policy_id);
		$criteria->compare('note',$this->note,true);
		$criteria->compare('createdby',$this->createdby);
		$criteria->compare('createdtime',$this->createdtime,true);
		$criteria->compare('updatedby',$this->updatedby);
		$criteria->compare('updatedtime',$this->updatedtime,true);
		$criteria->compare('biaya_kartu',$this->biaya_kartu);
		$criteria->compare('value_brokerage',$this->value_brokerage);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}


	public function searchView($id)
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
		$criteria->condition = 'id='.$id;

		$criteria->compare('id',$this->id);
		$criteria->compare('nota_no',$this->nota_no,true);
		$criteria->compare('endorsement_no',$this->endorsement_no,true);
		$criteria->compare('nominal',$this->nominal);
		$criteria->compare('admin_broker',$this->admin_broker);
		$criteria->compare('stamp_duty',$this->stamp_duty);
		$criteria->compare('stampduty_asuransi',$this->stampduty_asuransi);
		$criteria->compare('discount',$this->discount);
		$criteria->compare('diskon_asuransi',$this->diskon_asuransi);
		$criteria->compare('due_date',$this->due_date,true);
		$criteria->compare('nett_to_insurance',$this->nett_to_insurance);
		$criteria->compare('posting',$this->posting);
		$criteria->compare('type_reg_policy',$this->type_reg_policy);
		$criteria->compare('reg_policy_id',$this->reg_policy_id);
		$criteria->compare('note',$this->note,true);
		$criteria->compare('createdby',$this->createdby);
		$criteria->compare('createdtime',$this->createdtime,true);
		$criteria->compare('updatedby',$this->updatedby);
		$criteria->compare('updatedtime',$this->updatedtime,true);
		$criteria->compare('biaya_kartu',$this->biaya_kartu);
		$criteria->compare('value_brokerage',$this->value_brokerage);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return GantiKartu the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}


	public function getPeriodePolis($reg_policy_id, $type_reg_policy){

		if($type_reg_policy=='1'){
			$startPeriode = RegHealthPolicy::model()->findByPk($reg_policy_id)->start_periode;
			$endPeriode = RegHealthPolicy::model()->findByPk($reg_policy_id)->end_periode;
		}
		else{
			$startPeriode = RegHealthPolicyNon::model()->findByPk($reg_policy_id)->start_periode;
			$endPeriode = RegHealthPolicyNon::model()->findByPk($reg_policy_id)->end_periode;
		}
		
		$periodePolis = date('d-m-Y',strtotime($startPeriode))." s/d ".date('d-m-Y',strtotime($endPeriode));
		return $periodePolis;
	}


	public function getNoPolis($reg_policy_id, $type_reg_policy){

		if($type_reg_policy=='1'){
			$policyNo = RegHealthPolicy::model()->findByPk($reg_policy_id)->policy_no;
		}
		else{
			$policyNo = RegHealthPolicyNon::model()->findByPk($reg_policy_id)->policy_no;
		}
		
		return $policyNo;
	}



	public function getKlien($reg_policy_id, $type_reg_policy){

		if($type_reg_policy=='1'){
			$clientId = RegHealthPolicy::model()->findByPk($reg_policy_id)->mst_client_id;
			$clientName = MstClient::model()->findByPk($clientId)->name;
		}
		else{
			$clientId = RegHealthPolicyNon::model()->findByPk($reg_policy_id)->mst_client_id;
			$clientName = MstClient::model()->findByPk($clientId)->name;
		}
		
		return $clientName;
	}

}
